from django import forms
from django.forms import fields_for_model
from books.models import Publisher
TOPIC_CHOICES = ( 
    ('general', 'General enquiry'), 
    ('bug', 'Bug report'), 
    ('suggestion', 'Suggestion'),
)
class ContactForm(forms.Form):
    topic = forms.ChoiceField(choices=TOPIC_CHOICES)
    message = forms.CharField(widget = forms.Textarea())
    sender = forms.EmailField(required=False)

    def clean_message(self):
        message = self.cleaned_data.get('message','')
        num_words = len(message.split()) 
        if num_words < 4:
            raise forms.ValidationError("Not enough words!")
        return message
    def __unicode(self):
        return 'contact_form'

PublisherForm = fields_for_model(Publisher)